The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.
CHANGES 03
Functional.pm 825
META.yml 1018
3 files changed (This is a version diff) 1846
@@ -1,5 +1,8 @@
 Revision history for Perl module Functional.
 
+0.05 Sun Jul 24 15:20:19 BST 2011
+    - make all and any work on infinite lists (patch by Petr Pisar)
+
 0.04 Fri Dec 12 22:15:30 GMT 2008
     - rename Changes to CHANGES
     - move test to t/
@@ -8,7 +8,7 @@ use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS $INFINITE);
 require Exporter;
 
 @ISA = qw(Exporter);
-$VERSION = '0.04';
+$VERSION = '0.05';
 $INFINITE = 8192;
 
 my @methods = qw(show inc double square cons max min even odd 
@@ -1320,9 +1320,18 @@ In Haskell:
 
 sub any(&$) {
   my($p, $xs) = @_;
-  map {
-    return 1 if $p->($_);
-  } @{$xs};
+  my $n = 0;
+  my $size = $#{$xs};
+  while ($n <= $size) {
+    return 1 if $p->($xs->[$n]);
+    $n++;
+  }
+  if ($size == $Language::Functional::INFINITE
+      or $size == $Language::Functional::INFINITE - 1
+  ) {
+    confess "Evaluating predicate on inifinite number of elements " .
+      "would never end!";
+  }
   return 0;
 }
 
@@ -1345,10 +1354,18 @@ In Haskell:
 
 sub all(&$) {
   my($p, $xs) = @_;
-  map {
-    my $x = $_;
-    return 0 if not $p->($x);
-  } @{$xs};
+  my $n = 0;
+  my $size = $#{$xs};
+  while ($n <= $size) {
+    return 0 if not $p->($xs->[$n]);
+    $n++;
+  }
+  if ($size == $Language::Functional::INFINITE
+      or $size == $Language::Functional::INFINITE - 1
+  ) {
+    confess "Evaluating predicate on inifinite number of elements " .
+      "would never end!";
+  }
   return 1;
 }
 
@@ -1,13 +1,21 @@
 --- #YAML:1.0
-name:                Language-Functional
-version:             0.04
-abstract:            a module which makes Perl slightly more functional
-license:             perl
-author:              
+name:               Language-Functional
+version:            0.05
+abstract:           a module which makes Perl slightly more functional
+author:
     - Leon Brocard <acme@astray.com>
-generated_by:        ExtUtils::MakeMaker version 6.44
-distribution_type:   module
-requires:     
+license:            perl
+distribution_type:  module
+configure_requires:
+    ExtUtils::MakeMaker:  0
+build_requires:
+    ExtUtils::MakeMaker:  0
+requires:  {}
+no_index:
+    directory:
+        - t
+        - inc
+generated_by:       ExtUtils::MakeMaker version 6.56
 meta-spec:
-    url:     http://module-build.sourceforge.net/META-spec-v1.3.html
-    version: 1.3
+    url:      http://module-build.sourceforge.net/META-spec-v1.4.html
+    version:  1.4